﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FFS.BLL;
using FFS.Model;

namespace FFS
{
    public partial class frmModifyLoginPassword : Form
    {
        public frmModifyLoginPassword()
        {
            InitializeComponent();
        }

        LoginUserInfo user = new LoginUserInfo();
        LoginUserService userService = new LoginUserService();

        private void frmModifyLoginPassword_Load(object sender, EventArgs e)
        {
            this.txt_loginUserName.Text = Context._Login_UserName;
            this.txt_loginOldPassword.Text = "";
            this.txt_loginNewPassword.Text = "";
            this.txt_loginConfirmPassword.Text = "";
            this.txt_loginOldPassword.Focus();
            this.AcceptButton = this.btn_save;
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            string verifyString = "";
            if (this.txt_loginOldPassword.Text.ToString().Trim() == "")
            {
                verifyString = "旧密码不能为空\n";
            }
            else
            {
                if (!userService.ManageLoginUser().VerifyLogin(this.txt_loginUserName.Text.ToString().Trim(), this.txt_loginOldPassword.Text.ToString().Trim()))
                {
                    verifyString = "用户旧密码错误\n";
                    this.txt_loginOldPassword.SelectAll();
                }
            }
            if (this.txt_loginNewPassword.Text.ToString().Trim() == "")
            {
                verifyString += "新密码不能为空\n";
            }
            if (this.txt_loginConfirmPassword.Text.ToString().Trim() == "")
            {
                verifyString += "确认密码不能为空\n";
            }

            if (verifyString.Trim() == "")
            {
                if (this.txt_loginConfirmPassword.Text.ToString().Trim() != this.txt_loginNewPassword.Text.ToString().Trim())
                {
                    MessageBox.Show("新密码和确认密码不匹配\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    user.LoginUserName = this.txt_loginUserName.Text.ToString().Trim();
                    user.LoginPassword = this.txt_loginNewPassword.Text.ToString().Trim();
                    user.Input_User = Context._Login_UserName;
                    userService.ManageLoginUser().ModifyLoginUserPassword(user);
                    MessageBox.Show("密码修改成功\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show(verifyString,"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }
    }
}
